package com.jinsi.controller.yrf;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jinsi.constant.YrfConstant;
import com.jinsi.pojo.OperationLog;
import com.jinsi.service.yrf.OperationLogService;
import com.jinsi.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author: 86185
 * @description: 操作日志
 * @date 2022/9/8
 */
@RestController
@RequestMapping("/operationLog")
public class OperationLogController {

    @Autowired
    private OperationLogService operationLogService;

    /**
     *获取所有数据(模糊查询)
     * @param actionListName 模糊查
     * @param operationType 模糊查
     * @param executionTime 模糊查
     * @param administratorName 模糊查
     * @param limit 分页
     * @return 返回前端需要的类型
     */

    @RequestMapping("/getAll")
    public R getAll(Integer page, Integer limit, String administratorName,
                                       String actionListName, String operationType, Date executionTime){
        PageHelper.startPage(page,limit);
        List<OperationLog> all = operationLogService.getAll(administratorName,actionListName,
                operationType,executionTime);

        PageInfo<OperationLog> pageInfo = new PageInfo<>(all);

        return R.custom(YrfConstant.LAYUI_CODE,
                YrfConstant.LAYUI_MSG,
                pageInfo.getList(),
                pageInfo.getTotal());

    }

    /**
     * 删除操作日志行
     * @param operationLogId 根据operationLogId删除
     * @return 状态码
     */
    @RequestMapping("/del")
    public R operationLogdelete(int operationLogId){
        operationLogService.operationLogdelete(operationLogId);
        return R.ok("成功");
    }

    /**
     * 删除操作日志多行
     * @param arr 传入选中行id，遍历删除
     * @return 状态码
     */
    @RequestMapping("/delAll")
    public R delAll(@RequestParam("arr[]") ArrayList<Integer> arr){

        operationLogService.delAll(arr);
        return R.ok("成功");
    }
}
